/**
 * @param {string} s
 * @return {string}
 */
var longestPalindrome = function (s) {
  let res = ""
  for (let i = 0; i < s.length; i++) {
    // 奇数
    let l = i - 1
    let r = i + 1
    while (l >= 0 && r < s.length && s[l] == s[r]) r++, l--
    if (res.length < r - l - 1) res = s.substr(l + 1, r - l - 1)
    // 偶数
    l = i
    r = i + 1
    while (l >= 0 && r < s.length && s[l] == s[r]) r++, l--
    if (res.length < r - l - 1) res = s.substr(l + 1, r - l - 1)
  }
  return res
};